package com.example.javafx.simple;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.MenuItem;
import javafx.scene.control.SplitMenuButton;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class SplitMenuButtonExample extends Application {

    @Override
    public void start(Stage primaryStage) {
        // 创建一个 SplitMenuButton
        SplitMenuButton splitMenuButton = new SplitMenuButton();
        splitMenuButton.setText("Choose Option");

        // 添加 MenuItem 项
        MenuItem item1 = new MenuItem("Option 1");
        MenuItem item2 = new MenuItem("Option 2");
        MenuItem item3 = new MenuItem("Option 3");

        splitMenuButton.getItems().addAll(item1, item2, item3);

        // 设置主按钮的点击事件
        splitMenuButton.setOnAction(event -> {
            System.out.println("Main button clicked!");
        });

        // 将 SplitMenuButton 添加到布局
        VBox root = new VBox(splitMenuButton);
        Scene scene = new Scene(root, 300, 200);

        primaryStage.setTitle("SplitMenuButton Example");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}